Add luminosity_distance to LensingCosmology#289
Merged
Conversation
Implements D_L(z) = (1+z)^2 * D_A(0,z) returning Mpc, matching astropy's convention. Fixes AttributeError in workspace scripts that call cosmo.luminosity_distance(). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a luminosity_distance(z, xp=np) helper to LensingCosmology to provide an astropy-compatible luminosity distance (returned as a unitless float in Mpc) for the project’s custom JAX/NumPy cosmology implementation, addressing downstream workspace scripts that expect this API.
Changes:
- Implement
LensingCosmology.luminosity_distance(z, xp=np)using (D_L(z) = (1+z)^2 D_A(0,z)), converting kpc → Mpc. - Add a regression test validating
luminosity_distanceforPlanck15atz=0.1.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
autogalaxy/cosmology/model.py |
Adds luminosity_distance method returning Mpc using the existing angular-diameter distance implementation and xp backend. |
test_autogalaxy/cosmology/test_model.py |
Adds a unit test to validate the new luminosity distance value for Planck15 at low redshift. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
luminosity_distance(z, xp=np)toLensingCosmologyinautogalaxy/cosmology/model.pyD_L(z) = (1 + z)^2 * D_A(0, z), returns Mpc matching astropy's conventionAttributeError: 'FlatLambdaCDM' object has no attribute 'luminosity_distance'raised by workspace scripts (e.g.autolens_workspace/scripts/guides/units/mass_to_light_ratio_units.py)Test plan
test_autogalaxy/cosmology/test_model.py::test__luminosity_distance— verifies value against knownD_Afor Planck15 at z=0.1🤖 Generated with Claude Code